﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;

using CE.Configuration;
using CE.Global;
using CE.User;
using CE.Image;
using CE.Mail;
using CE.CMI;
using CE.Database;
using CE.Payment;
using CE.CarInsurance;

public partial class car_insurance_proposalforms_cmi_form : MyLanguageBasePage
{
    public static Int64 _CarId, _CarMoreId, _UserId, _CXCTypeId, _ProviderId, _AgentId;

    protected void Page_Load(object sender, EventArgs e)
    {
        Master.Page.Title = Resources.Title.CompulsuryInsurance;

        if (!IsPostBack)
        {
            if (Session[General.CMIId] != null)
            {
                if (Session[General.ProviderCompanyId] == null)
                {
                    if (Session[CE.Global.General.UserId] != null)
                    {
                        _redirectUrl = CE.Global.General.GetUrl("~/user/saved-quotes.aspx", Page);
                        Response.Redirect(_redirectUrl);
                    }
                    else
                    {
                        _redirectUrl = CE.Global.General.GetUrl("~/cmi/cmi-main.aspx", Page);
                        Response.Redirect(_redirectUrl);
                    }
                }
                _CarId = Convert.ToInt64(Session[General.CMICarId].ToString());
                FillIn();

                Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();
            }
            else
            {
                Response.Redirect("~/cmi/cmi-select.aspx");
            }
        }
    }

    #region Load

    private void FillIn()
    {
        CMI _cmi = new CMI();
        CMIDB _cmidb = new CMIDB();
        _cmi = _cmidb.GetCMI(Convert.ToInt64(Session[General.CMIId]));

        if (_cmi.CTPLProviderCompanyId > 0) GetInsurance(_cmi.CTPLProviderCompanyId);
        if (_cmi.CMIDate != null)
        {
            lblCTPLDate.Text = _cmi.CMIDate.Value.ToString("dd") + "/" + _cmi.CMIDate.Value.ToString("MM") + "/" + _cmi.CMIDate.Value.ToString("yyyy");
        }

        if (_cmi.RegistrationDate != null)
        {
            divTaxRenewal.Style.Add("display", "");
            lblRegistrationDate.Text = _cmi.RegistrationDate.Value.ToString("dd") + "/" + _cmi.RegistrationDate.Value.ToString("MM") + "/" + _cmi.RegistrationDate.Value.ToString("yyyy");

            if (_cmi.CarType != '1')
            {
                divCarWeight.Style.Add("display", "");
                lblCarWeight.Text = _cmi.CarWeight;
            }
        }

        if (_cmi.CTPLAmout > 0) lblSumCTPL.Text = _cmi.CTPLAmout.ToString();
        if (_cmi.CTPLDiscount > 0) lblSumDiscount.Text = _cmi.CTPLDiscount.ToString();
        if (_cmi.TaxRenewalAmount > 0) lblSumTaxAndPanalty.Text = _cmi.TaxRenewalAmount.ToString();
        if (_cmi.ChargedAmount > 0) lblSumCharged.Text = _cmi.ChargedAmount.ToString();
        if (_cmi.EMS > 0) lblSumEMS.Text = _cmi.EMS.ToString();
        if (_cmi.CMITotal > 0) lblTotal.Text = _cmi.CMITotal.ToString();

        if (CultureInfo.CurrentCulture.Name != "th-TH")
        {
            lblManYear.Text = _cmi.ManufactYear.ToString();

            string[] colorTH = {"ขาว","เขียว","ชมพู","ดำ","แดง","ทอง","เทา","น้ำตาล","น้ำเงิน","บรอนซ์",
                                 "ฟ้า","ม่วง","ส้ม","เหลือง","บรอนซ์เงิน","บรอนซ์ทอง"};
            string[] colorEN = {"White","Green","Pink","Black","Red","Golden","Gray","Brown","Blue","Bronze",
                                 "Light blue","Purple","Orange","Yellow","Silver","Golden bronze"};

            for (int i = 0; i < colorTH.Length; i ++)
            {
                if (_cmi.CarColor == colorTH[i])
                {
                    lblCarColor.Text = colorEN[i];
                    break;
                }
            }

        }
        else
        {
            lblManYear.Text = _cmi.ManufactYear.ToString() + " - พ.ศ. " + (_cmi.ManufactYear + 543).ToString();
            lblCarColor.Text = _cmi.CarColor;
        }
        
        lblCarMake.Text = _cmi.CarMake;
        string _tempDesc = _cmi.CarModel + " " + _cmi.Body + " " + _cmi.CC + "cc " + _cmi.Door.ToString() + " doors";
        lblModelBodyCCDoor.Text = _tempDesc;

        lblChassisNo.Text = _cmi.ChassisNo;
        lblEngineNumber.Text = _cmi.EngineNumber;
        lblEngineSize.Text = _cmi.EngineSize;

        lblName.Text = _cmi.Name;
        lblOwnerName.Text = _cmi.OwnerName;
        lblPlateNumber.Text = _cmi.CarPlate;
        lblProvince.Text = _cmi.Province;
        lblAddress.Text = _cmi.Address;
        lblEmailAddress.Text = _cmi.Email;
        lblMobileNo.Text = _cmi.Mobile;
        if (_cmi.IsSameAddress)
        {
            lblDeliveryAddress.Text = _cmi.Address;
            lblDeliveryName.Text = _cmi.Name;
        }
        else
        {
            lblDeliveryAddress.Text = _cmi.DeliveryAddress;
            lblDeliveryName.Text = _cmi.DeliveryName;
        }

        string convertno = General.GetRefNumber(_CarId);
        lblQRefNo.Text = "CMI" + convertno.ToString();
        
    }

    //public void LoadCarPolicyDetailsViriyah()
    //{
    //    //if (Session[CE.Global.General.UserId] != null)
    //    //{
    //    //    _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
    //    //}
    //    //else
    //    //{
    //    //    _UserId = 0;
    //    //}
    //    ////_CarId = Convert.ToInt64(Session[General.CMICarId].ToString());
    //    ////_CXCTypeId = Convert.ToInt64(Session[CE.Global.General.CarResultId].ToString());
    //    ////_ProviderId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());
    //    ////DataSet _dtProvider = new DataSet();
    //    ////ViriyahCarMoreDetail _viriyahcarmoredetail = new ViriyahCarMoreDetail();
    //    ////ViriyahCarMoreDetailDB _viriyahcarmoredetaildb = new ViriyahCarMoreDetailDB();
    //    ////_dtProvider = _viriyahcarmoredetaildb.GetCarPolicyDetails(_CarId, _UserId, _CXCTypeId, _ProviderId);
    //    ////if (_dtProvider != null && _dtProvider.Tables.Count > 0)
    //    ////{
    //    ////    if (_dtProvider.Tables[0].Rows.Count > 0 && _dtProvider.Tables[1].Rows.Count > 0 && _dtProvider.Tables[2].Rows.Count > 0)
    //    ////    {
    //    ////    }
    //    ////    else
    //    ////    {
    //    ////        //Response.Redirect("~/user/usermessage.aspx?mt=CI&ec=502");
    //    ////        _redirectUrl = CE.Global.General.GetUrl("~/user/usermessage.aspx", Page);
    //    ////        Session["UMMSG"] = "CI,502";
    //    ////        Response.Redirect(_redirectUrl);
    //    ////    }
    //    ////}
    //    ////else
    //    ////{
    //    ////    //Response.Redirect("~/user/usermessage.aspx?mt=CI&ec=502");
    //    ////    _redirectUrl = CE.Global.General.GetUrl("~/user/usermessage.aspx", Page);
    //    ////    Session["UMMSG"] = "CI,502";
    //    ////    Response.Redirect(_redirectUrl);
    //    ////}

    //    string convertno = General.GetRefNumber(_CarId);
    //    if (_ProviderId == 11)
    //    {
    //        lblQRefNo.Text = "AZC" + convertno.ToString();
    //    }
    //    else if (_ProviderId == 12)
    //    {
    //        lblQRefNo.Text = "MSI" + convertno.ToString();
    //    }
    //    else if (_ProviderId == 16)
    //    {
    //        lblQRefNo.Text = "AXA" + convertno.ToString();
    //    }
    //    else if (_ProviderId == 29)
    //    {
    //        lblQRefNo.Text = "LMG" + convertno.ToString();
    //    }
    //    else if (_ProviderId == 31)
    //    {
    //        lblQRefNo.Text = "CTS" + convertno.ToString();
    //    }
    //    else if (_ProviderId == 32)
    //    {
    //        lblQRefNo.Text = "BKI" + convertno.ToString();
    //    }
    //    else if (_ProviderId == 33)
    //    {
    //        lblQRefNo.Text = "MTI" + convertno.ToString();
    //    }
    //    else if (_ProviderId == 35)
    //    {
    //        lblQRefNo.Text = "KPI" + convertno.ToString();
    //    }
    //    else if (_ProviderId == 41)
    //    {
    //        lblQRefNo.Text = "KUR" + convertno.ToString();
    //    }
    //    else if (_ProviderId == 45)
    //    {
    //        lblQRefNo.Text = "VRY" + convertno.ToString();
    //    }
    //    else if (_ProviderId == 46)
    //    {
    //        lblQRefNo.Text = "TMS" + convertno.ToString();
    //    }
    //}

    #endregion

    #region Insurance

    private void GetInsurance(Int64 CTPLProviderCompanyId)
    {
        try
        {
            MyDatabase _db = new MyDatabase();
            object objC;
            if (System.Globalization.CultureInfo.CurrentCulture.Name == "th-TH")
            {
                objC = _db.ExecuteScalarSqlStatement("SELECT THCompanyNameDescription AS CompanyName FROM tblProviderCompany WHERE ProviderCompanyId=" + CTPLProviderCompanyId.ToString());
            }
            else
            {
                objC = _db.ExecuteScalarSqlStatement("SELECT CompanyNameDescription AS CompanyName FROM tblProviderCompany WHERE ProviderCompanyId=" + CTPLProviderCompanyId.ToString());
            }

            if (objC != null)
            {
                lblCTPLProviderCompany.Text = objC.ToString();
            }
        }
        catch (Exception ex)
        {
        }
    }

    #endregion

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("MI", Request, "CMI form.");
    }

    protected void ibtSubmit_Click(object sender, EventArgs e)
    {
        //if (Session[CE.Global.General.UserId] != null)
        if (IsValid)
        {
            SubmitPayment();
            if (SendCMIToUser())
            {
                ibtSubmit.Enabled = false;
            }
            else
            {
                lblMessage.Text = "Fail sending email.";
            }
        }
    }

    string _redirectUrl = "";
    private void SubmitPayment()
    {
        //Int64 _carmoreresult = 0;
        //Int64 driverresult = 0;
        //ViriyahCarMoreDetail _viriyahcarmoredetail = new ViriyahCarMoreDetail();
        //ViriyahCarMoreDetailDB _viriyahcarmoredetaildb = new ViriyahCarMoreDetailDB();

        //if (Session[General.CarMoreDetailId] != null)
        //{
        //    _viriyahcarmoredetail.CECarMoreDetailId = Convert.ToInt64(Session[General.CarMoreDetailId].ToString());
        //}
        //else
        //{
        //    _viriyahcarmoredetail.CECarMoreDetailId = 0;
        //}
        //_viriyahcarmoredetail.CECarId = Convert.ToInt64(Session[General.CMICarId].ToString());
        //_viriyahcarmoredetail.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());

        //float _VarPremium = Convert.ToSingle(lblTotal.Text); //txtPremium

        //_viriyahcarmoredetail.AnnualPremium = _VarPremium;

        //_viriyahcarmoredetail.TermPremium = (_viriyahcarmoredetail.AnnualPremium / 4);

        //_viriyahcarmoredetail.Name = lblName.Text.Trim();
        //_viriyahcarmoredetail.IdentificationNo = "";
        //_viriyahcarmoredetail.Occupation = "54"; //Others
        //_viriyahcarmoredetail.ContactNo = lblMobileNo.Text;
        //_viriyahcarmoredetail.OfficePhoneNo = "";
        //_viriyahcarmoredetail.BeneficiaryName = lblOwnerName.Text;

        //_viriyahcarmoredetail.CarPlate = lblPlateNumber.Text;
        //_viriyahcarmoredetail.CarPlateProvince = lblProvince.Text;
        //_viriyahcarmoredetail.PresentAddress = lblAddress.Text;
        //_viriyahcarmoredetail.SubDistrict = "";
        //_viriyahcarmoredetail.District = "";
        //_viriyahcarmoredetail.Province = "";
        //_viriyahcarmoredetail.PostalCode = "";
        //if (lblDeliveryAddress.Text.Trim() != "")
        //{
        //    _viriyahcarmoredetail.IsMailingAddressDiff = true;
        //    _viriyahcarmoredetail.MailingAddress = lblDeliveryAddress.Text;
        //}
        //else
        //{
        //    _viriyahcarmoredetail.IsMailingAddressDiff = false;
        //    _viriyahcarmoredetail.MailingAddress = "";
        //}
        //_viriyahcarmoredetail.MailingSubDistrict = "";
        //_viriyahcarmoredetail.MailingDistrict = "";
        //_viriyahcarmoredetail.MailingProvince = "";
        //_viriyahcarmoredetail.MailingPostalCode = "";
        //_viriyahcarmoredetail.EngineNumber = lblEngineNumber.Text;
        //_viriyahcarmoredetail.ChassisNumber = lblChassisNo.Text;
        //_viriyahcarmoredetail.IsCTPL = true;
        //_viriyahcarmoredetail.CTPL = Convert.ToSingle(lblSumCTPL.Text) - Convert.ToSingle(lblSumDiscount.Text);

        //if (rdoBankIn.Checked == true)
        //{
        //    _viriyahcarmoredetail.PaymentType = "Bank In";
        //    switch (rdoBankInOption.SelectedItem.Value)
        //    {
        //        case "BKK":
        //            _viriyahcarmoredetail.PaymentBank = "BKK";
        //            break;
        //        case "KBANK":
        //            _viriyahcarmoredetail.PaymentBank = "KBANK";
        //            break;
        //        case "KTB":
        //            _viriyahcarmoredetail.PaymentBank = "KTB";
        //            break;
        //        case "SCB":
        //            _viriyahcarmoredetail.PaymentBank = "SCB";
        //            break;
        //    }
        //}
        //else if (rdoCreditCard.Checked == true)
        //{
        //    _viriyahcarmoredetail.PaymentType = "CreditCard";

        //}

        //_viriyahcarmoredetail.OrderRefNoId = GetOrderRefNoId();
        //_viriyahcarmoredetail.OrderRefNo = GetOrderRefNo();
        //_viriyahcarmoredetail.PaymentStatus = false;

        //_viriyahcarmoredetail.QuoteRefNo = lblQRefNo.Text.Trim();

        //if (Session[CE.Global.General.UserId] != null)
        //{
        //    _viriyahcarmoredetail.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        //}
        //else
        //{
        //    _viriyahcarmoredetail.RefCEUserId = 0;
        //}

        //_viriyahcarmoredetail.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
        //_viriyahcarmoredetail.Status = true;
        //_viriyahcarmoredetail.CarResultId = 779452; // Convert.ToInt64(Session[General.CMIId]); //Convert.ToInt64(Session[General.CarResultId].ToString());
        //if (Session[CE.Global.General.AgentId] != null)
        //{
        //    _viriyahcarmoredetail.Ninfo4 = Convert.ToInt64(Session[CE.Global.General.AgentId].ToString());
        //    if (rdoBankIn.Checked == true)
        //    {
        //        _viriyahcarmoredetail.Ninfo5 = 102;
        //    }
        //    else if (rdoCreditCard.Checked == true)
        //    {
        //        _viriyahcarmoredetail.Ninfo5 = 202;
        //    }
        //}
        //else
        //{
        //    _viriyahcarmoredetail.Ninfo4 = 0;
        //    _viriyahcarmoredetail.Ninfo5 = 0;
        //}

        //_carmoreresult = _viriyahcarmoredetaildb.Insert(_viriyahcarmoredetail);

        //if (_carmoreresult > 0)
        //{
        //    Session[CE.Global.General.CarMoreDetailId] = _carmoreresult.ToString();
        //    Int64 _paymentresult = 0;

        //    _paymentresult = 1;
        //    if (_paymentresult > 0)
        //    {
        //        driverresult = 1;
        //        if (driverresult > 0)
        //        {
        //            Session[CE.Global.General.CarMoreDetailId] = _carmoreresult.ToString();
        //            UserConfirmation _userconfirm = new UserConfirmation();
        //            UserConfirmationDB _userconfirmdb = new UserConfirmationDB();
        //            _userconfirm.ConfirmationType = "CI";
        //            _userconfirm.CurrentStep = 4;
        //            _userconfirm.UserSelectedId = 779452; //Convert.ToInt64(Session[General.CMIId]); //Convert.ToInt64(Session[General.CarResultId].ToString());
        //            _userconfirm.FirstStepId = Convert.ToInt64(Session[General.CMICarId].ToString());
        //            if (Session[General.UserId] != null)
        //            {
        //                _userconfirm.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
        //            }
        //            else
        //            {
        //                _userconfirm.RefCEUserId = 0;
        //            }
        //            _userconfirm.IsConfirm = true;

        //            _userconfirm.ResultStatus = "Complete";
        //            _userconfirm.IsComplete = true;
        //            Int64 _result = _userconfirmdb.Insert(_userconfirm);
        //            if (_result > 0)
        //            {
        //                string _provideid = Encode(Session[General.ProviderCompanyId].ToString());
        //                string _refid = "";
        //                string convertno = General.GetRefNumber(Convert.ToInt64(Session[CE.Global.General.CMICarId]));
        //                _refid = "A" + convertno;

        //                if (Session[General.CarResultId] != null)
        //                {
        //                    //SendProposalToAgent(Session[General.CarResultId].ToString());
        //                }
        //                if (rdoBankIn.Checked)
        //                {
        //                    ProposalNotification();
        //                    General.ClearAllSession(this.Page, "ALL");
        //                    //Response.Redirect("~/car-insurance/usermessage.aspx?pcid=" + _provideid + "&ref=" + _refid);
        //                    _redirectUrl = CE.Global.General.GetUrl("~/car-insurance/usermessage.aspx", Page);
        //                    Session["CIMSG"] = _provideid + "," + _refid + "," + "OTHER";
        //                    Response.Redirect(_redirectUrl);
        //                }
        //                else if (rdoCreditCard.Checked)
        //                {
        //                    float _fAmount = _viriyahcarmoredetail.AnnualPremium;
        //                    //float _fAmount = Convert.ToSingle(txtPremium.Text);
        //                    string _strAmount, eAmount, _strOrderRefNo, eOrderRefNo;
        //                    _strAmount = ""; eAmount = ""; _strOrderRefNo = ""; eOrderRefNo = "";
        //                    string key = "cxDAtravel";
        //                    CXDecryption.Decryption cxd = new CXDecryption.Decryption();
        //                    _strAmount = _fAmount.ToString();
        //                    _strOrderRefNo = _viriyahcarmoredetail.OrderRefNo;
        //                    if (_strAmount.ToString() != "" && _strAmount.ToString() != null)
        //                    {
        //                        byte[] Amount = cxd.Encrypt(_strAmount, key);
        //                        eAmount = Convert.ToBase64String(Amount);
        //                    }
        //                    if (_strOrderRefNo.ToString() != "" && _strOrderRefNo.ToString() != null)
        //                    {
        //                        byte[] OrderRefNo = cxd.Encrypt(_strOrderRefNo, key);
        //                        eOrderRefNo = Convert.ToBase64String(OrderRefNo);
        //                    }
        //                    string URL = ConfigurationManager.AppSettings["TH.BKKPaymentPage"].ToString();
        //                    URL += "?pa=" + eAmount + "&orno=" + eOrderRefNo;
        //                    //string URL = "http://203.142.18.110/bkk_test/MethodOne.aspx?pa=" + eAmount + "&orno=" + eOrderRefNo;
        //                    Response.Redirect(URL);
        //                }
        //            }
        //            else
        //            {
        //                lblMessage.Text = "Can't update confirmation status.";
        //            }
        //        }
        //    }
        //}

        CMIDB _cmidb = new CMIDB();

        UserConfirmation _userconfirm = new UserConfirmation();
        UserConfirmationDB _userconfirmdb = new UserConfirmationDB();
        _userconfirm.ConfirmationType = "CI";
        _userconfirm.CurrentStep = 4;
        _userconfirm.UserSelectedId = 779452; //Convert.ToInt64(Session[General.CMIId]); //Convert.ToInt64(Session[General.CarResultId].ToString());
        _userconfirm.FirstStepId = Convert.ToInt64(Session[General.CMICarId].ToString());
        if (Session[General.UserId] != null)
        {
            _userconfirm.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
        }
        else
        {
            _userconfirm.RefCEUserId = 0;
        }
        _userconfirm.IsConfirm = true;

        _userconfirm.ResultStatus = "Complete";
        _userconfirm.IsComplete = true;

        Int64 _result = _userconfirmdb.Insert(_userconfirm);
        if (_result > 0)
        {
            string _provideid = Encode(Session[General.ProviderCompanyId].ToString());
            string _refid = "";
            _refid = Session[CE.Global.General.CMICarId].ToString();
            //string convertno = General.GetRefNumber(Convert.ToInt64(Session[CE.Global.General.CMICarId]));
            //_refid = "A" + convertno;

            //if (Session[General.CarResultId] != null)
            //{
            //    //SendProposalToAgent(Session[General.CarResultId].ToString());
            //}

            //if (rdoBankIn.Checked)
            //{
            //    ProposalNotification();

            //    _cmidb.UpdateStatus(Int64.Parse(Session[General.CMIId].ToString()), "BANK");
            //    Session["CMIDTL"] = _provideid + "," + Session[General.CMIId].ToString();
            //    General.ClearAllSession(this.Page, "ALL");
            //    //Response.Redirect("~/car-insurance/usermessage.aspx?pcid=" + _provideid + "&ref=" + _refid);
            //    _redirectUrl = CE.Global.General.GetUrl("~/cmi/usermessagecmi.aspx", Page);
            //    Response.Redirect(_redirectUrl);
            //}
            //else 
            
            if (rdoCreditCard.Checked)
            {
                string _orderRefNo = GetOrderRefNo();
                _cmidb.UpdateStatus(Int64.Parse(Session[General.CMIId].ToString()), _orderRefNo, lblQRefNo.Text, "CREDIT");
                SendProposalToAgent(Session[General.CMIId].ToString());
                Session[General.CMIId] = null;

                float _fAmount = Convert.ToSingle(lblTotal.Text);
                //float _fAmount = Convert.ToSingle(txtPremium.Text);
                string _strAmount, eAmount, _strOrderRefNo, eOrderRefNo;
                _strAmount = ""; eAmount = ""; _strOrderRefNo = ""; eOrderRefNo = "";
                string key = "cxDAtravel";
                CXDecryption.Decryption cxd = new CXDecryption.Decryption();
                _strAmount = _fAmount.ToString();
                _strOrderRefNo = _orderRefNo;
                if (_strAmount.ToString() != "" && _strAmount.ToString() != null)
                {
                    byte[] Amount = cxd.Encrypt(_strAmount, key);
                    eAmount = Convert.ToBase64String(Amount);
                }
                if (_strOrderRefNo.ToString() != "" && _strOrderRefNo.ToString() != null)
                {
                    byte[] OrderRefNo = cxd.Encrypt(_strOrderRefNo, key);
                    eOrderRefNo = Convert.ToBase64String(OrderRefNo);
                }
                //string URL = ConfigurationManager.AppSettings["TH.BKKPaymentPage"].ToString();
                //URL += "?pa=" + eAmount + "&orno=" + eOrderRefNo;
                string URL = "http://localhost:88/MethodOne.aspx?pa=" + eAmount + "&orno=" + eOrderRefNo;
                Response.Redirect(URL);
            }
        }
        else
        {
            lblMessage.Text = "Can't update confirmation status.";
        }
    }

    //private bool CheckConfirmStatus()
    //{
    //    bool _retValue = false;
    //    Int64 _CarId = 0;
    //    ViriyahCarMoreDetailDB _viriyahcarmoredetaildb = new ViriyahCarMoreDetailDB();
    //    if (Session[General.CMICarId] != null)
    //    {
    //        _CarId = Convert.ToInt64(Session[General.CMICarId].ToString());
    //    }
    //    Int64 _checkResult = _viriyahcarmoredetaildb.CheckConfirmStatus(_CarId, "CI");
    //    if (_checkResult > 0)
    //    {
    //        _retValue = true;
    //    }
    //    else
    //    {
    //        _retValue = false;
    //    }
    //    return _retValue;
    //}

    private Int64 GetOrderRefNoId()
    {
        Int64 _retValue = 0;
        Int64 _OrderId = 0;
        ViriyahCarMoreDetailDB _viriyahcarmoredetaildb = new ViriyahCarMoreDetailDB();
        if (Session[General.CMICarId] != null)
        {
            _CarId = Convert.ToInt64(Session[General.CMICarId].ToString());
        }
        MyDatabase _db = new MyDatabase();
        string strSql = "SELECT OrderRefNoId FROM [tblCarMoreDetail_Viriyah] ORDER BY CECarMoreDetailId DESC ";
        object _result = _db.ExecuteScalarSqlStatement(strSql);
        if (_result != null)
        {
            _OrderId = Convert.ToInt64(_result.ToString());
        }
        _retValue = _OrderId + 1;

        return _retValue;
    }

    public string GetOrderRefNo()
    {
        Int64 CarId = 0;
        if (Session[CE.Global.General.CMICarId] != null)
            CarId = Convert.ToInt64(Session[CE.Global.General.CMICarId].ToString());
        string _result = "";
        string _onoffline = "1";
        string _firstno = DateTime.Now.ToString("yy") + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00") +
                          DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00");
        _result = _firstno + _onoffline + CarId.ToString("000000000");
        return _result;
    }

    private void ProposalNotification()
    {
        string _strMailActive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsMailActive");
        if (_strMailActive == "1")
        {
            string _strSql, _providerName, _ToEmail, _CCEmail, _BCCEmail, _Date, _Time, _InsuranceName, _RefNo;
            MyDatabase _db = new MyDatabase();
            DataTable _dtProvider = new DataTable();
            DataTable _dtInsurance = new DataTable();
            _Date = "";
            _Time = "";
            _RefNo = "";
            _strSql = "";
            _providerName = "";
            _ToEmail = "";
            _CCEmail = "";
            _BCCEmail = "";
            _InsuranceName = Resources.WelcomeEmail.CarInsurance; //"Car Insurance";

            _ToEmail = Session[General.UserEmail].ToString();
            if (Session[General.ProviderCompanyId] != null && Session[General.CMICarId] != null)
            {
                _ProviderId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
                _CarId = Convert.ToInt64(Session[General.CMICarId].ToString());
            }
            _strSql = "SELECT [CompanyName], [Email1], [PhoneNo1] FROM tblProviderCompany WHERE ProviderCompanyId = " + _ProviderId.ToString();

            _dtProvider = _db.GetDataTable(_strSql);
            if (_dtProvider.Rows.Count > 0)
            {
                _providerName = _dtProvider.Rows[0]["CompanyName"].ToString();
                _CCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.CI_CC");
                _BCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.CI_BCC");
            }
            _strSql = "";
            _strSql = "SELECT CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time] ";
            _strSql += " FROM  tblCarMoreDetail_Viriyah WHERE CECarId = " + _CarId.ToString() + " ORDER BY ModifiedDate DESC";
            _dtInsurance = _db.GetDataTable(_strSql);
            if (_dtInsurance.Rows.Count > 0)
            {
                _Date = _dtInsurance.Rows[0]["Date"].ToString();
                _Time = _dtInsurance.Rows[0]["Time"].ToString();
            }
            _RefNo = lblQRefNo.Text.Trim();
            if ((_dtProvider.Rows.Count > 0) && (_dtInsurance.Rows.Count > 0))
            {
                //SendProposalToUserNEW(Session[General.CarResultId].ToString());
            }
        }
    }

    public string Encode(string sData)
    {
        byte[] encData_byte = new byte[sData.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
        string encodedData = Convert.ToBase64String(encData_byte);
        return encodedData;
    }

    private bool SendProposalToAgent(string CMIId)
    {
        Int64 _carId = Convert.ToInt64(Session[General.CMICarId].ToString());
        CE.User.Profile usrprofile = new Profile();
        ProfileDB usrprofiledb = new ProfileDB();

        usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[General.UserId].ToString()));

        string userfirstname = "";

        if (usrprofile != null)
        {
            userfirstname = usrprofile.FirstName;
        }

        string _refNo = "";
        CarDetailTH _cardetailth = new CarDetailTH();
        CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
        CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
        DataSet _dsInsurance = new DataSet();

        string _CarYear = "";
        string _CarMakeModel = "";
        string _CarType = "";
        string _CarPlate = "";
        string _Name = "";
        string _serviceType = "";

        Int64 _companyId = 0;

        CMI _cmi = new CMI();
        CMIDB _cmidb = new CMIDB();
        _cmi = _cmidb.GetCMI(Convert.ToInt64(Session[General.CMIId]));
        _companyId = _cmi.CTPLProviderCompanyId;

        _CarYear = _cmi.ManufactYear.ToString();
        _CarMakeModel = _cmi.MakeModelDesc;

        if (_cmi.ServiceType == '1')
            _serviceType = Resources.EmailMessage.CMISubject1.ToString();
        else if (_cmi.ServiceType == '2')
            _serviceType = Resources.EmailMessage.CMISubject2.ToString();
        else if (_cmi.ServiceType == '3')
            _serviceType = Resources.EmailMessage.CMISubject3.ToString();

        if (_cmi.CarType == '1')
            _CarType = GetGlobalResourceObject("CarInsurance", "VehicleType1").ToString();
        else if (_cmi.CarType == '2')
            _CarType = GetGlobalResourceObject("CarInsurance", "VehicleType2").ToString();
        else if (_cmi.CarType == '3')
            _CarType = GetGlobalResourceObject("CarInsurance", "VehicleType3").ToString();


        _CarPlate = _cmi.CarPlate.ToString();

        _Name = _cmi.Name;
        _refNo = _cmi.QuoteRefNo.ToString();


        bool _retVal = false;
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");

        string _emailTo = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_TO"].ToString();
        string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_CC"].ToString();
        string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_BCC"].ToString();
        string _customername = Session[General.UserName].ToString();
        string _emailSubject = "";
        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Authority.ToString();
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LogoPath");
        string _providercompanyid = _cmi.CTPLProviderCompanyId.ToString();
        string _companyName = "";
        if (_providercompanyid == "11")
        {
            _companyName = "AZCP Insurance";
        }
        else if (_providercompanyid == "29")
        {
            _companyName = "LMG Insurance";
        }
        else if (_providercompanyid == "12")
        {
            _companyName = "MSIG Insurance";
        }
        else if (_providercompanyid == "16")
        {
            _companyName = "AXA Insurance";
        }
        else if (_providercompanyid == "31")
        {
            _companyName = "Chartis Insurance";
        }
        else if (_providercompanyid == "32")
        {
            _companyName = "Bangkok Insurance";
        }
        else if (_providercompanyid == "41")
        {
            _companyName = "Kurnia Insurance";
        }

        _emailSubject = "<Online> - " + Resources.Proposal.PendingPayment + " - " + _serviceType + "-" + _companyName;

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center> <br /><br />";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' width='570'>";
        _mailBody += "<tr><td width='570'><table cellspacing='0' cellpadding='0' width='100%' border='0'>";
        if (Session[CE.Global.General.AgentId] != null && Session[CE.Global.General.AgentName] != null)
        {
            _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.Proposal.PendingPayment + " - " + Session[CE.Global.General.AgentName].ToString() + "</strong><br /><br />";
        }
        else
        {
            _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.Proposal.PendingPayment + "</strong><br /><br />";
        }
        _mailBody += Resources.Proposal.AgentMessage + "<br/><br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.OrderNo + " </strong>" + _cmi.OrderRefNo + "</td><td width='50%' align='right' valign='top'><img src='" + _currentDomainUrl + "/images/public/logo/logo_gluaygluay.png' width='130' height='99'/></td></tr>";
        _mailBody += "</table>";

        _mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.RefNo + ": " + _refNo + "</td><td valign='top'>" + Resources.Proposal.OrderDate + ": " + DateTime.Now.ToString("dd/MMM/yyyy") + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.NameLastname + ": " + _Name + "</td><td valign='top'>" + Resources.Proposal.LicensePlateNo + ": " + _CarPlate + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.MakeModel + ": " + _CarMakeModel + "</td><td valign='top'>" + Resources.Proposal.CarYear + ": " + _CarYear + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.CarInsurance.CTPLStartDate + ": " + _cmi.CMIDate + " </td><td valign='top'></td></tr>";
        _mailBody += "</table> <br /><br />";



        _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='100%' class='table_details'>";



        //if (dtResults.Rows.Count > 0)
        //{
        //logo
        string logourl = CE.Global.General.GetProviderCompanyLogo(_providercompanyid);

        _mailBody += "<tr>";
        _mailBody += "<td width='45%'></td>";
        _mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
        _mailBody += "</tr>";

        //cmi Session["CMICTPL"].ToString();
        //cmi discount Session["CMICTPLDISC"].ToString();
        //if (Session["CMITOTAL"] != null) lblTotal.Text = Session["CMITOTAL"].ToString();
        //if (Session["CMITOTAL"] != null) hidTotal.Value = Session["CMITOTAL"].ToString();


        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Insurer + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + _companyName + "</ br>" + _CarType + "</strong></td>";
        _mailBody += "</tr>";



        string CMIPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.CTPLAmout.ToString()));
        if (CMIPrice == "0")
        {
            CMIPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string CMIDiscount = String.Format("{0:#,0}", Convert.ToSingle(_cmi.CTPLDiscount.ToString()));
        if (CMIDiscount == "0")
        {
            CMIDiscount = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string TaxAndPanaltyPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.TaxRenewalAmount.ToString()));
        if (TaxAndPanaltyPrice == "0")
        {
            TaxAndPanaltyPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string ChargedPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.ChargedAmount.ToString()));
        if (ChargedPrice == "0")
        {
            ChargedPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string EMSPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.EMS.ToString()));
        if (EMSPrice == "0")
        {
            EMSPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string TotalPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.CMITotal.ToString()));

        //CTPL"
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.ResultPage.CTPL + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + CMIPrice + "</td>";
        _mailBody += "</tr>";

        //Discount
        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsurance.Discount + "</strong></td>";
        _mailBody += "<td align='center' style='background:#c5c5c5' >" + CMIDiscount + "</td>";
        _mailBody += "</tr>";

        //TaxAndPanalty
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsurance.TaxAndPanalty + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + TaxAndPanaltyPrice + "</td>";
        _mailBody += "</tr>";

        //Charged
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsurance.Charged + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + ChargedPrice + "</td>";
        _mailBody += "</tr>";


        //EMS
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsurance.EMS + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + EMSPrice + "</td>";
        _mailBody += "</tr>";


        //premium
        _mailBody += "<tr>";
        _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.TotalVMI + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

        _mailBody += "<br/><strong>" + TotalPrice + "</strong>";



        _mailBody += "</td>";
        _mailBody += "</tr>";


        //}

        _mailBody += "</table>";
        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'>";
        _mailBody += "</td></tr></table>";
        _mailBody += "</center></body>";

        if (MyMailManager.SendSelectedCARMessageToAgent(_emailTo, _emailCC, _emailBCC, _emailSubject + " (Ref No : " + _refNo + ") ", _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    //private bool SendProposalToUserNEW(string CITempResultId)
    //{
    //    Int64 _carId = Convert.ToInt64(Session[General.CMICarId].ToString());
    //    CE.User.Profile usrprofile = new Profile();
    //    ProfileDB usrprofiledb = new ProfileDB();

    //    usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[General.UserId].ToString()));

    //    string userfirstname = "";

    //    if (usrprofile != null)
    //    {
    //        userfirstname = usrprofile.FirstName;
    //    }

    //    string _refNo = "";
    //    CarDetailTH _cardetailth = new CarDetailTH();
    //    CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
    //    CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
    //    DataSet _dsInsurance = new DataSet();

    //    string _Premium = "";
    //    string _Gender = "";
    //    string _DOB = "";
    //    string _Occupation = "";
    //    string _InsuranceType = "";
    //    string _NCB = "";

    //    string _GarageType = "";
    //    string _CarYear = "";
    //    string _CarMakeModel = "";
    //    string _CarType = "";
    //    string _CarPlate = "";
    //    string _NameDriver = "";
    //    string _Name = "";
    //    string _PolicyStartDate = "";

    //    string _isCTPL = "No";
    //    string _CTPL = "";

    //    Int64 _companyId = 0;

    //    System.Data.DataTable _dtSeletectItem = new System.Data.DataTable("SelectedResultItem");
    //    _dtSeletectItem = _db.GetDataTable("Select * from tblCarInsuranceSelectItemTH WHERE CarId = " + _carId.ToString());
    //    if (_dtSeletectItem != null && _dtSeletectItem.Rows.Count > 0)
    //    {
    //        _companyId = Convert.ToInt64(_dtSeletectItem.Rows[0]["ProviderCompanyId"].ToString());
    //        _Premium = Convert.ToSingle(_dtSeletectItem.Rows[0]["AnnualPremium"].ToString()).ToString("#.00");
    //    }
    //    CarInsuranceCompletedItemDB _carinsurancecompleteditemdb = new CarInsuranceCompletedItemDB();
    //    _dsInsurance = _carinsurancecompleteditemdb.GetCarInsuranceCompletedItem(_carId, _companyId);
    //    if (_dsInsurance != null && _dsInsurance.Tables[0].Rows.Count > 0)
    //    {
    //        _Gender = _dsInsurance.Tables[0].Rows[0]["Gender"].ToString() == "Male" ? Resources.CarInsurance.Male : Resources.CarInsurance.Female;
    //        _DOB = Convert.ToDateTime(_dsInsurance.Tables[0].Rows[0]["DOB"]).ToString("dd-MMM-yyyy");
    //        if (CE.Global.General.SetCulture() == "th-TH")
    //        {
    //            _Occupation = _dsInsurance.Tables[0].Rows[0]["THOccupation"].ToString();
    //        }
    //        else
    //        {
    //            _Occupation = _dsInsurance.Tables[0].Rows[0]["ENOccupation"].ToString();
    //        }
    //        //lblInsuranceType.Text = _dsInsurance.Tables[0].Rows[0]["InsuranceType"].ToString();
    //        switch (_dsInsurance.Tables[0].Rows[0]["InsuranceType"].ToString())
    //        {
    //            case "Class 1":
    //                _InsuranceType = Resources.CarInsurance.Insurance_ClassOne;
    //                _NCB = _dsInsurance.Tables[0].Rows[0]["NCB"].ToString();
    //                break;
    //            case "Class 1 (Low Cost)":
    //                _InsuranceType = Resources.CarInsurance.Insurance_ClassOneLowCost;
    //                _NCB = "N/A";
    //                break;
    //            case "Class 2+":
    //                _InsuranceType = Resources.CarInsurance.Insurance_ClassTwoPlus;
    //                _NCB = "N/A";
    //                break;
    //            case "Class 3+":
    //                _InsuranceType = Resources.CarInsurance.Insurance_ClassThreePlus;
    //                _NCB = "N/A";
    //                break;
    //            case "Class 3":
    //                _InsuranceType = Resources.CarInsurance.Insurance_ClassThree;
    //                _NCB = "N/A";
    //                break;
    //        }



    //        _GarageType = _dsInsurance.Tables[0].Rows[0]["GarageType"].ToString() == "Authorized" ? Resources.CarInsurance.Garage_Authorized : Resources.CarInsurance.Garage_Dealer;
    //        _CarYear = _dsInsurance.Tables[0].Rows[0]["CarModelYear"].ToString();
    //        _CarMakeModel = _dsInsurance.Tables[0].Rows[0]["MakeModelDesc"].ToString();
    //        _CarType = _dsInsurance.Tables[0].Rows[0]["VehicleType"].ToString() == "Private Use" ? Resources.CarInsurance.VehicleType_Private : Resources.CarInsurance.VehicleType_Commercial;
    //        _NameDriver = _dsInsurance.Tables[0].Rows[0]["Driver"].ToString() == "Yes" ? Resources.CarInsurance.Option_YesSpecify : Resources.CarInsurance.Option_NoSpecify;

    //        if (_dsInsurance.Tables[1].Rows.Count > 0)
    //        {

    //            _CarPlate = _dsInsurance.Tables[1].Rows[0]["VehicleNo"].ToString();
    //            if (_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"] != DBNull.Value)
    //            {
    //                _PolicyStartDate = Convert.ToDateTime(_dsInsurance.Tables[1].Rows[0]["PolicyStartDate"]).ToString("dd-MMM-yyyy");
    //            }
    //            _Name = _dsInsurance.Tables[1].Rows[0]["Name"].ToString();
    //            _refNo = _dsInsurance.Tables[1].Rows[0]["QuoteRefNo"].ToString();

    //            _isCTPL = _dsInsurance.Tables[1].Rows[0]["CTPL"].ToString();
    //            _CTPL = _dsInsurance.Tables[1].Rows[0]["CTPLAmount"].ToString();
    //        }
    //        //lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : " + _refNo + " - " + Resources.CarInsurance.CarInsuranceList + " " + lblCarMakeModel.Text;
    //    }

    //    bool _retVal = false;
    //    string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");

    //    string _emailTo = Session[General.UserEmail].ToString();
    //    //string _emailTo = "sophon.vorasitchai@comparexpress.com";
    //    string _customername = Session[General.UserName].ToString();
    //    string _emailSubject = "<Online> - " + Resources.EmailMessage.Subject; // "Your Car Insurance Quotes on CompareXpress(Thailand)";
    //    string _mailBody = "";
    //    string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString(); //for testing
    //    //string _currentDomainUrl = "http://www.กล้วยๆ.com";
    //    string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LogoPath");

    //    _mailBody = "<body class='email_body'>";
    //    _mailBody += "<style type='text/css'>";
    //    _mailBody += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
    //    _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
    //    _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
    //    _mailBody += "#email_body {width:100%; text-align: left !important;} ";
    //    _mailBody += ".email_pad10px {padding:10px;} ";
    //    _mailBody += ".email_results td {width:33%;} ";
    //    _mailBody += "</style>";
    //    _mailBody += "<center> <br /><br />";

    //    _mailBody += "<table cellpadding='0' cellspacing='0' border='0' width='570'>";
    //    _mailBody += "<tr><td width='570'><table cellspacing='0' cellpadding='0' width='100%' border='0'>";
    //    _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.Proposal.OrderConfirmation + "</strong><br /><br />";
    //    _mailBody += Resources.Proposal.ThankYou + "<br/><br/>";
    //    _mailBody += "<br/><strong>" + Resources.Proposal.OrderNo + "</strong> " + _refNo + "</td><td width='50%' align='right' valign='top'><img src='" + _currentDomainUrl + "/images/public/logo/logo_gluaygluay.png' width='130' height='99'/></td></tr>";
    //    _mailBody += "</table>";

    //    _mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
    //    _mailBody += " <tr><td width='50%' valign='top'>" + Resources.Proposal.InsuranceType + " " + _InsuranceType + "</td><td width='50%;' valign='top'>&nbsp;</td>";
    //    _mailBody += "</tr><tr><td valign='top'>" + Resources.Proposal.RefNo + ": " + _refNo + "</td><td valign='top'>" + Resources.Proposal.OrderDate + ": " + DateTime.Now.ToString("dd/MMM/yyyy") + "</td></tr>";
    //    _mailBody += "<tr><td valign='top'>" + Resources.Proposal.NameLastname + ": " + _Name + "</td><td valign='top'>" + Resources.Proposal.LicensePlateNo + ": " + _CarPlate + "</td></tr>";
    //    _mailBody += "<tr><td valign='top'>" + Resources.Proposal.MakeModel + ": " + _CarMakeModel + "</td><td valign='top'>" + Resources.Proposal.CarYear + ": " + _CarYear + "</td></tr>";
    //    _mailBody += "<tr><td valign='top'>" + Resources.Proposal.GarageType + ": " + _GarageType + "</td><td valign='top'>" + Resources.Proposal.NamedDrivers + ": " + _NameDriver + "</td></tr>";
    //    _mailBody += "<tr><td valign='top'>" + Resources.Proposal.PolicyStartDate + ": " + _PolicyStartDate + " </td><td valign='top'>" + Resources.Proposal.NCB + ": " + _NCB + "</td></tr>";
    //    _mailBody += "</table> <br /><br />";

    //    //Sakthi on 18 Jan 2012 -- Start
    //    DataSet _dsResults = new DataSet();
    //    DataView dvResults = new DataView();
    //    SortedList _sPara = new SortedList();

    //    _sPara.Add("@CarId", Convert.ToInt64(Session[General.CMICarId].ToString()));
    //    _sPara.Add("@RefUserId", Convert.ToInt64(Session[General.UserId].ToString()));
    //    _dsResults = _db.GetDataSet("sprocCarInsuranceResultSelectItemList", _sPara);
    //    if (_dsResults.Tables.Count > 0 && _dsResults.Tables[0].Rows.Count > 0)
    //    {
    //        dvResults = _dsResults.Tables[0].DefaultView;
    //        dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";
    //    }
    //    //DataView dvResults = new DataView((DataTable)Cache["CarResult" + Session[General.UserId].ToString() + Session[General.CMICarId].ToString()]);
    //    //Sakthi on 18 Jan 2012 -- End

    //    _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='100%' class='table_details'>";

    //    //string CITempResultId = inputCarResultId.Value;
    //    dvResults.RowFilter = " CITempResultId in (" + CITempResultId + ")";

    //    DataTable dtResults = dvResults.ToTable();


    //    if (dtResults.Rows.Count > 0)
    //    {
    //        string _providercompanyid = dtResults.Rows[0]["providercompanyid"].ToString();
    //        //logo
    //        string logourl = CE.Global.General.GetProviderCompanyLogo(_providercompanyid);

    //        _mailBody += "<tr>";
    //        _mailBody += "<td width='45%'></td>";
    //        _mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
    //        _mailBody += "</tr>";

    //        string insurername = dtResults.Rows[0]["PackageName"].ToString();

    //        //insurer name
    //        _mailBody += "<tr>";
    //        _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Insurer + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + insurername + "</strong></td>";
    //        _mailBody += "</tr>";


    //        float _fMonthlyPremiumAmount = Convert.ToSingle(dtResults.Rows[0]["MonthlyPremiumAmount"].ToString());
    //        string monthlyInstallment = "";

    //        if (_fMonthlyPremiumAmount > 0.0f)
    //        {
    //            string _monthlyPremiumAmount = String.Format("{0:0,0.00}", _fMonthlyPremiumAmount);
    //            monthlyInstallment = _monthlyPremiumAmount + "/mth<br/>";
    //        }
    //        else
    //        {
    //            monthlyInstallment = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
    //        }

    //        //installment
    //        //_mailBody += "<tr>";
    //        //_mailBody += "<td><strong>"+ Resources.CarInsuranceResultPage.MonthlyInstallment  +" <br/>4-mth 0% Interest Free</strong></td>";
    //        //_mailBody += "<td align='center' style='background:#d5d5d5' >" + monthlyInstallment + "</td>";
    //        //_mailBody += "</tr>";

    //        //Deductible  
    //        _mailBody += "<tr>";
    //        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.DEC + "</strong></td>";
    //        float _fDEC = Convert.ToSingle(dtResults.Rows[0]["DEC"].ToString());
    //        string deductible = "";
    //        if (_fDEC > 0.0f)
    //        {
    //            deductible = String.Format("{0:0,0.00}", _fDEC);
    //        }
    //        else
    //        {
    //            deductible = Resources.CarInsuranceResultPage.Waived;  //"<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
    //        }
    //        _mailBody += "<td align='center' style='background:#c5c5c5' >" + deductible + "</td>";
    //        _mailBody += "</tr>";

    //        string suminsured = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["SumInsured"].ToString()));
    //        if (suminsured == "0")
    //        {
    //            suminsured = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
    //        }
    //        //Own Damage
    //        _mailBody += "<tr>";
    //        _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.OwnDamage + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#d5d5d5' >" + suminsured + "</td>";
    //        _mailBody += "</tr>";

    //        //Fire
    //        string fire = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["Fire"].ToString()));
    //        if (fire == "0")
    //        {
    //            fire = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
    //        }
    //        _mailBody += "<tr>";
    //        _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Fire + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#c5c5c5' >" + fire + "</td>";
    //        _mailBody += "</tr>";

    //        //Theft
    //        string theft = String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["Theft"].ToString()));
    //        if (theft == "0")
    //        {
    //            theft = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
    //        }
    //        _mailBody += "<tr>";
    //        _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Theft + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#d5d5d5' >" + theft + "</td>";
    //        _mailBody += "</tr>";

    //        //TPPD
    //        _mailBody += "<tr>";
    //        _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.TPPD + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#c5c5c5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPPD"].ToString())) + "</td>";
    //        _mailBody += "</tr>";

    //        //TPBIA
    //        _mailBody += "<tr>";
    //        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.TPBIA + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIA"].ToString())) + "</td>";
    //        _mailBody += "</tr>";

    //        //TPBIP
    //        _mailBody += "<tr>";
    //        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.TPBIP + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#c5c5c5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["TPBIP"].ToString())) + "</td>";
    //        _mailBody += "</tr>";

    //        //PA Driver
    //        _mailBody += "<tr>";
    //        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.PADriver + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["PADriver"].ToString())) + "</td>";
    //        _mailBody += "</tr>";


    //        int _MedicalExpense = Convert.ToInt32(dtResults.Rows[0]["MedicalExpense"].ToString());
    //        string medicalExpense = "";

    //        if (_MedicalExpense == 0)
    //        {
    //            medicalExpense = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
    //        }
    //        else
    //        {
    //            medicalExpense = String.Format("{0:#,0}", Convert.ToSingle(_MedicalExpense.ToString()));
    //        }

    //        //Medical Expense
    //        _mailBody += "<tr>";
    //        _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.MED + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#c5c5c5' >" + medicalExpense + "</td>";
    //        _mailBody += "</tr>";

    //        //BB
    //        _mailBody += "<tr>";
    //        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsuranceResultPage.BailBond + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#d5d5d5' >" + String.Format("{0:#,0}", Convert.ToSingle(dtResults.Rows[0]["BailBond"].ToString())) + "</td>";
    //        _mailBody += "</tr>";

    //        //CTPL
    //        if (_isCTPL == "Yes")
    //        {
    //            //premium before ctpl
    //            _mailBody += "<tr>";
    //            _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.AnnualPremium + "</strong></td>";
    //            _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

    //            double BeforeCTPL = Convert.ToSingle(_Premium) - Convert.ToSingle(_CTPL);

    //            if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
    //            {
    //                _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
    //            }

    //            _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(BeforeCTPL)) + "</strong>";
    //            _mailBody += "</td>";
    //            _mailBody += "</tr>";

    //            //ctplamount
    //            _mailBody += "<tr>";
    //            _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.CTPL + "</strong></td>";
    //            _mailBody += "<td align='center' style='background:#d5d5d5;'>";

    //            _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(_CTPL)) + "</strong>";
    //            _mailBody += "</td>";
    //            _mailBody += "</tr>";

    //        }


    //        //premium
    //        _mailBody += "<tr>";
    //        _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.TotalVMI + "</strong></td>";
    //        _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

    //        if (_isCTPL == "No")
    //        {
    //            if (Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) != Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"]))
    //            {
    //                _mailBody += "<s>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
    //            }

    //            _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["PromotionPrice"].ToString())) + "</strong>";
    //        }
    //        else
    //        {
    //            _mailBody += "<br/><strong>" + String.Format("{0:0,0.00}", Convert.ToSingle(_Premium)) + "</strong>";
    //        }

    //        _mailBody += "</td>";
    //        _mailBody += "</tr>";

    //    }

    //    _mailBody += "</table>";
    //    _mailBody += "<br/><br/>";
    //    _mailBody += "<u>" + Resources.Proposal.ForBankIn + "</u>";
    //    _mailBody += "<br/>" + Resources.Proposal.ForBankInMsg1;


    //    _mailBody += "<br/>";

    //    _mailBody += "<br/>" + Resources.Proposal.ForBankInMsg2;

    //    _mailBody += "<br/>";

    //    _mailBody += "<br/><strong>" + Resources.Proposal.Remarks + "</strong>";
    //    _mailBody += "<br/>" + Resources.Proposal.RemarksMsg1;
    //    _mailBody += "<br/>";
    //    _mailBody += "<br/><strong>" + Resources.Proposal.CompareXpress + "</strong>";
    //    _mailBody += "<br/>" + Resources.Proposal.CompareXpressAddress;

    //    _mailBody += "</td></tr>";
    //    _mailBody += "<tr><td id='email_footer'>";
    //    _mailBody += "</td></tr></table>";

    //    _mailBody += "<hr />";
    //    _mailBody += Resources.EmailMessage.Footer;
    //    _mailBody += "<br/>";
    //    _mailBody += "<br /><i>" + Resources.EmailMessage.NoReply + "</i>";
    //    _mailBody += "<hr />";
    //    _mailBody += "</center></body>";

    //    if (MyMailManager.SendSelectedCARMessage(_emailTo, _emailSubject + " (Ref No : " + _refNo + ") ", _mailBody))
    //    {
    //        _retVal = true;
    //    }
    //    else
    //    {
    //        _retVal = false;
    //    }

    //    return _retVal;
    //}

    #region Email

    private bool SendCMIToUser()
    {
        bool _retVal = false;
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");

        string _emailTo = lblEmailAddress.Text;
        string _emailSubject = "";
        if (Session["CMISERVICE"].ToString() == "1")
        {
            _emailSubject = "<Online> - " + Resources.EmailMessage.CMISubject1;
        }
        else if (Session["CMISERVICE"].ToString() == "2")
        {
            _emailSubject = "<Online> - " + Resources.EmailMessage.CMISubject2;
        }
        else if (Session["CMISERVICE"].ToString() == "3")
        {
            _emailSubject = "<Online> - " + Resources.EmailMessage.CMISubject3;
        }

        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LogoPath");

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center> <br /><br />";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' width='570'>";
        _mailBody += "<tr><td width='570'><table cellspacing='0' cellpadding='0' width='100%' border='0'>";
        _mailBody += "<tr><td width='50%' valign='top'><strong>" + Session["CMITITLE"].ToString() + "</strong><br /><br />";
        _mailBody += Resources.Proposal.ThankYou + "<br/><br/>";
        _mailBody += "<br/></td><td width='50%' align='right' valign='top'><img src='" + _currentDomainUrl + "/images/public/logo/logo_gluaygluay.png' width='130' height='99'/></td></tr>";
        _mailBody += "</table>";

        _mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
        _mailBody += "<tr><td width='25%' valign='top'><strong>" + Resources.ResultPage.CTPL + "</strong></td>";
        _mailBody += "<td width='25%' valign='top'><strong>" + Resources.CarInsurance.TaxAndPanalty + "</strong></td>";
        _mailBody += "<td width='25%' valign='top'><strong>" + Resources.CarInsurance.Charged + "</strong></td>";
        _mailBody += "<td width='25%' valign='top'><strong>" + Resources.CarInsurance.Total + "</strong></td></tr>";

        _mailBody += "<tr><td valign='top'>" + lblSumCTPL.Text + "</td>";
        _mailBody += "<td valign='top'>" + lblSumTaxAndPanalty.Text + "</td>";
        _mailBody += "<td valign='top'>" + lblSumCharged.Text + "</td>";
        _mailBody += "<td valign='top'>" + lblTotal.Text + "</td></tr>";
        _mailBody += "</table> <br /><br />";

        _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='100%' class='table_details'>";

        //_mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
        //_mailBody += " <tr><td width='50%' valign='top'>" + Resources.Proposal.InsuranceType + " " + _InsuranceType + "</td><td width='50%;' valign='top'>&nbsp;</td>";
        //_mailBody += "</tr><tr><td valign='top'>" + Resources.Proposal.RefNo + ": " + _refNo + "</td><td valign='top'>" + Resources.Proposal.OrderDate + ": " + DateTime.Now.ToString("dd/MMM/yyyy") + "</td></tr>";
        //_mailBody += "<tr><td valign='top'>" + Resources.Proposal.NameLastname + ": " + _Name + "</td><td valign='top'>" + Resources.Proposal.LicensePlateNo + ": " + _CarPlate + "</td></tr>";
        //_mailBody += "<tr><td valign='top'>" + Resources.Proposal.MakeModel + ": " + _CarMakeModel + "</td><td valign='top'>" + Resources.Proposal.CarYear + ": " + _CarYear + "</td></tr>";
        //_mailBody += "<tr><td valign='top'>" + Resources.Proposal.GarageType + ": " + _GarageType + "</td><td valign='top'>" + Resources.Proposal.NamedDrivers + ": " + _NameDriver + "</td></tr>";
        //_mailBody += "<tr><td valign='top'>" + Resources.Proposal.PolicyStartDate + ": " + _PolicyStartDate + " </td><td valign='top'>" + Resources.Proposal.NCB + ": " + _NCB + "</td></tr>";
        //_mailBody += "</table> <br /><br />";

        //_mailBody += "<tr>";
        //_mailBody += "<td width='45%'></td>";
        //_mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
        //_mailBody += "</tr>";
        //_mailBody += "<tr>";
        //_mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Insurer + "</strong></td>";
        //_mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + insurername + "</strong></td>";
        //_mailBody += "</tr>";

        //divCarDetail
        if (Session["CMISERVICE"].ToString() != "3")
        {
            _mailBody += "<tr>";
            _mailBody += "<td></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5'><strong>" + Resources.CarInsurance.CarAndInsuranceDetail + "</strong></td>";
            _mailBody += "</tr>";

            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsurance.CarModelYear + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblManYear.Text + "</td>";
            _mailBody += "</tr>";

            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsurance.CarMakeModel + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblCarMake.Text + " - " + lblModelBodyCCDoor.Text + "</td>";
            _mailBody += "</tr>";

            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsurance.ChassisNo + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblChassisNo.Text + "</td>";
            _mailBody += "</tr>";

            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsurance.EngineNumber + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblEngineNumber.Text + "</td>";
            _mailBody += "</tr>";

            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsurance.EngineSize + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblEngineSize.Text + "</td>";
            _mailBody += "</tr>";

            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsurance.CTPLStartDate + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblCTPLDate.Text + "</td>";
            _mailBody += "</tr>";
        }

        //divCarTaxDetail
        if (Session["CMISERVICE"].ToString() != "1")
        {
            _mailBody += "<tr>";
            _mailBody += "<td></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5'><strong>" + Resources.CarInsurance.TaxRenewalDetail + "</strong></td>";
            _mailBody += "</tr>";

            _mailBody += "<tr>";
            _mailBody += "<td><strong>" + Resources.CarInsurance.RegistrationDate + "</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblRegistrationDate.Text + "</td>";
            _mailBody += "</tr>";
        }

        _mailBody += "<tr>";
        _mailBody += "<td></td>";
        _mailBody += "<td align='center' style='background:#c5c5c5'><strong>" + Resources.CarInsurance.AssuredData + "</strong></td>";
        _mailBody += "</tr>";

        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsurance.Name + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblName.Text + "</td>";
        _mailBody += "</tr>";

        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsurance.OwnerName + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblOwnerName.Text + "</td>";
        _mailBody += "</tr>";

        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.ProposalForm.CarPlate + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblPlateNumber.Text + " " + lblProvince.Text + "</td>";
        _mailBody += "</tr>";

        //if (chkRedPlate.Checked)
        //{
        //    _mailBody += "<tr>";
        //    _mailBody += "<td><strong>" + Resources.CarInsurance.RedPlate + "</strong></td>";
        //    _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + Resources.CarInsurance.Option_Yes + "</td>";
        //    _mailBody += "</tr>";
        //}

        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsurance.AssuredAddress + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblAddress.Text + "</td>";
        _mailBody += "</tr>";

        _mailBody += "<tr>";
        _mailBody += "<td></td>";
        _mailBody += "<td align='center' style='background:#c5c5c5'><strong>" + Resources.CarInsurance.DeliveryInfo + "</strong></td>";
        _mailBody += "</tr>";

        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsurance.Name + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblDeliveryName.Text + "</td>";
        _mailBody += "</tr>";

        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsurance.DeliveryAddress + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5;border-bottom:1px solid #ccc;' >" + lblDeliveryAddress.Text + "</td>";
        _mailBody += "</tr>";

        _mailBody += "</table>";

        _mailBody += "<br/>";
        _mailBody += "<br/>";

        //_mailBody += "<u>" + Resources.Proposal.ForBankIn + "</u>";
        //_mailBody += "<br/>" + Resources.Proposal.ForBankInMsg1;
        //_mailBody += "<br/>";
        //_mailBody += "<br/>" + Resources.Proposal.ForBankInMsg2;
        //_mailBody += "<br/>";
        //_mailBody += "<br/><strong>" + Resources.Proposal.Remarks + "</strong>";
        //_mailBody += "<br/>" + Resources.Proposal.RemarksMsg1;
        //_mailBody += "<br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.CompareXpress + "</strong>";
        _mailBody += "<br/>" + Resources.Proposal.CompareXpressAddress;

        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'>";
        _mailBody += "</td></tr></table>";

        _mailBody += "<hr />";
        _mailBody += Resources.EmailMessage.Footer;
        _mailBody += "<br/>";
        _mailBody += "<br /><i>" + Resources.EmailMessage.NoReply + "</i>";
        _mailBody += "<hr />";
        _mailBody += "</center></body>";

        if (MyMailManager.SendSelectedCARMessage(_emailTo, _emailSubject, _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    #endregion

}
